﻿@model Sheng.WeixinConstruction.Client.Shell.Models.DonationViewModel

@{
    ViewBag.SubTitle = "活动";
    Layout = "~/Views/Shared/_LayoutBlank.cshtml";
}


<style type="text/css">
    body {
        margin-bottom: 0.55rem;
    }

    .campaignName {
        font-size: 0.14rem;
        font-weight: bold;
    }

    .campaignDescription {
        font-size: 0.13rem;
        color: #666;
    }

    #divMemberInfo {
        font-size: 0.14rem;
        line-height: 0.14rem;
        text-align: center;
        margin-top: 0.05rem;
    }



    #divShareMask {
        position: absolute;
        top: 0px;
        bottom: 0px;
        left: 0px;
        right: 0px;
        width: 100%;
        height: 100%;
        background-color: black;
        text-align: right;
        filter: alpha(opacity=80);
        -moz-opacity: 0.8;
        -khtml-opacity: 0.8;
        opacity: 0.8;
    }

    .divLuckyTicketItem {
        text-align: center;
        font-size: 0.12rem;
        color: #FF7F00;
        background-image: url(/Content/Images/bg_star.jpg);
        background-repeat: repeat;
        padding-top: 0.05rem;
        padding-bottom: 0.05rem;
        margin-bottom: 0.05rem;
    }

    #divFooter {
        position: fixed;
        bottom: 0px;
        left: 0px;
        right: 0px;
        height: 0.4rem;
        font-size: 0.14rem;
        text-align: center;
        background-color: #F5F5F5;
    }
</style>

<script>

    var _currentPage = 1;
    var _totalPage = 1;
    var _status = @((int)Model.CampaignBundle.Campaign.Status);
    var _campaignId = getQueryString("campaignId");

    var _validator;

    $(document).ready(function () {
        $(document).scroll(function () {
            $("#divShareMask").css("top", document.body.scrollTop);
        });

        var jsApiConfigStr = "@Newtonsoft.Json.JsonConvert.SerializeObject(Model.JsApiConfig)";
        jsApiConfigStr = jsApiConfigStr.replace(new RegExp("&quot;", "gm"), "\"");
        jsApiConfigStr = jsApiConfigStr.replace(new RegExp("\r\n", "gm"), "");
        jsApiConfigStr = jsApiConfigStr.replace(new RegExp("\n", "gm"), "");
        var jsApiConfig = eval('(' + jsApiConfigStr + ')');

        wx.config(jsApiConfig);

        loadData();

        _validator = $("#form").validate({
            onfocusout: false,
            onkeyup: false,
            showErrors: showValidationErrors,
            rules: {
                "txtFee": {
                    required: true,
                    number: true,
                    digits: true,
                    range: [1, 1000000]
                },
            },
            messages: {
                "txtFee": {
                    required: "请输入要充值的金额；",
                    number: "充值金额请输入有效整数字；",
                    digits: "充值金额请输入有效整数字；",
                    range: "充值金额请介于 1 到 1000000 之间；"
                },
            }
        });

        $("#txtFee").focus();

    });

    wx.ready(function () {
        wx.onMenuShareTimeline({
            title: '@Model.CampaignBundle.Campaign.ShareTimelineTitle', // 分享标题
            link: '@Request.Url.Scheme://@Request.Url.Host/Campaign/LuckyTicketShare/@Model.CampaignBundle.Campaign.Domain?campaignId=@Model.CampaignBundle.Campaign.Id&memberId=@ViewBag.Member.Id', // 分享链接
            imgUrl: '@Model.CampaignBundle.Campaign.ShareImageUrl', // 分享图标
            success: function () {
                shareSuccess("ShareTimeline");
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
            }
        });

        wx.onMenuShareAppMessage({
            title: '@Model.CampaignBundle.Campaign.ShareAppMessageTitle', // 分享标题
            desc: '@Model.CampaignBundle.Campaign.ShareAppMessageDescription', // 分享描述
            link: '@Request.Url.Scheme://@Request.Url.Host/Campaign/LuckyTicketShare/@Model.CampaignBundle.Campaign.Domain?campaignId=@Model.CampaignBundle.Campaign.Id&memberId=@ViewBag.Member.Id', // 分享链接
            imgUrl: '@Model.CampaignBundle.Campaign.ShareImageUrl', // 分享图标
            type: 'link', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                shareSuccess("ShareAppMessage");
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
            }
        });
    });

    wx.error(function (res) {
        alert("error:" + res);
    });

    function shareSuccess(type) {
        var loadLayerIndex = layer.open({
            type: 2,
            shadeClose: false,
            content: '请稍候...'
        });

        $.ajax({
            url: "/Api/Campaign/" + type + "/@ViewBag.Domain.Id?campaignId=" + _campaignId,
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR) {
                // alert(data);

                layer.close(loadLayerIndex);
                if (data.Success) {
                    var resultObj = data.Data;

                    if (resultObj.Point == 0)
                        return;

                    var msg = "";
                    if (resultObj.Point > 0) {
                        msg += "获得积分：" + resultObj.Point;
                    }
                    if (msg != "") {
                        layerAlertBtn(msg);
                    }

                } else {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest) {
                layer.close(loadLayerIndex);
                //alert("Error: " + xmlHttpRequest.status);
            }
        });
    }



    function showCampaignDescription() {
        var loadLayerIndex = layer.open({
            type: 2,
            shadeClose: false,
            content: '请稍候...'
        });

        $.ajax({
            url: "/Api/Campaign/GetCampaignDescription/@ViewBag.Domain.Id?id=" + _campaignId,
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR) {
                layer.close(loadLayerIndex);
                if (data.Success) {
                    var resultObj = data.Data;

                    var gettpl = document.getElementById('campaignDescription').innerHTML;

                    laytpl(gettpl).render(resultObj, function (html) {
                        var pageii = layer.open({
                            type: 1,
                            content: html,
                            shadeClose: false,
                            style: 'position:fixed; left:0.1rem; top:0.1rem;right:0.1rem; bottom:0.1rem; border:none;'
                        });
                    });

                } else {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest) {
                layer.close(loadLayerIndex);
                //alert("Error: " + xmlHttpRequest.status);
            }
        });

    }

    function showShareMask() {
        $("#divShareMask").css("top", document.body.scrollTop);
        $("#divShareMask").show();
        $("#divFooter").hide();
    }

    function hideShareMask() {
        $("#divShareMask").hide();
        $("#divFooter").show();
    }

    function deposit() {
       @if (ViewBag.DomainContext.Pay == false)
       {
           <text>
       layerAlert(@(ViewBag.Authorizer.NickName) 未开通对接微信支付，请使用线下现金充值方式为您的账户充值。);
           return;
           </text>
       }
        if (_validator.form() == false) {
            return;
        }

        var fee = $("#txtFee").val();

        var confirmLayerIndex = layer.open({
            content: '确认捐款人民币 ' + fee + ' 元吗？',
            btn: ['确认', '取消'],
            shadeClose: false,
            anim: false,
            yes: function () {
                layer.close(confirmLayerIndex);

                var loadLayerIndex = layer.open({
                    type: 2,
                    shadeClose: false,
                    content: '请稍候...'
                });

                var args = new Object();
                args.CampaignId  = _campaignId;
                args.Fee = fee;
                args.Name = $("#txtName").val();
                args.Contact = $("#txtContact").val();
                args.Description = $("#txtDescription").val();

                $.ajax({
                    url: "/Api/Campaign/DonationPay/@ViewBag.Domain.Id",
                    type: "POST",
                    dataType: "json",
                    data: JSON.stringify(args),
                    success: function (data, status, jqXHR) {

                        if (data.Success) {
                           // alert(JSON.stringify(data));

                            // window.location.href = "/Pay/PayOrderDetail/@ViewBag.Domain.Id?id=" + data.Data.PayOrderId;
                            var currentUrl = encodeURI(window.location.href);
                            window.location.href = '/Pay/PayOrderDetail/@ViewBag.Domain.Id?id=' + data.Data.Data.PayOrderId + "&action=1&returnUrl=" + currentUrl;


                        } else {
                            layer.close(loadLayerIndex);
                            layerAlert(data.Message);
                        }
                    },
                    error: function (xmlHttpRequest) {
                        layer.close(loadLayerIndex);
                        //alert("Error: " + xmlHttpRequest.status);
                    }
                });
            }
        });
    }

    function loadData() {

        

        var loadLayerIndex = layer.open({
            type: 2,
            shadeClose: false,
            content: '请稍候...'
        });

        var args = new Object();
        args.Page = 1;
        args.PageSize = 1000;
        args.CampaignId = _campaignId;

        $.ajax({
            url: "/Api/Campaign/GetDonationLogList/@ViewBag.Domain.Id",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR) {
                layer.close(loadLayerIndex);
                if (data.Success) {
                    var resultObj = data.Data;

                    _currentPage = resultObj.Page;
                    _totalPage = resultObj.TotalPage;

                    if(_currentPage==1)
                    {
                        document.getElementById('ticketNumberItemContainer').innerHTML = "";
                    }

                    var gettpl = document.getElementById('ticketNumberItemTemplate').innerHTML;
                    laytpl(gettpl).render(resultObj.ItemList, function (html) {
                        document.getElementById('ticketNumberItemContainer').innerHTML += html;
                    });

                } else {
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest) {
                layer.close(loadLayerIndex);
                //alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

    function payOrder(payOrderId){
        var currentUrl = encodeURI(window.location.href);
        window.location.href = '/Pay/PayOrderDetail/@ViewBag.Domain.Id?id=' + payOrderId ;
    }

</script>

<script type="text/html" id="campaignDescription">
    <div style="position: fixed; top: 0.1rem; left: 0.1rem; right: 0.1rem; bottom: 0.45rem; overflow: auto;">
        {{ d }}
    </div>
    <div style="position: fixed; bottom: 0.1rem; left: 0.1rem; right: 0.1rem;">
        <div class="divRectangle_Gray" style="margin-top: 0.1rem; " onclick="layer.closeAll()">
            关 闭
        </div>
    </div>
</script>

<script type="text/html" id="ticketNumberItemTemplate">
    {{# for(var i = 0, len = d.length; i < len; i=i+1){ }}
    {{# var fee = accDiv(d[i].TotalFee,100) }}
    <div class="divLuckyTicketItem" onclick="payOrder('{{ d[i].PayOrder }}')">
        {{ d[i].CreateTime }} 捐款 
        {{ fee }} 元
        {{# if(d[i].Finish){ }}
            
        {{# } else{}}
            (未完成）
        {{# } }}
    </div>
    {{# } }}
</script>




<div id="divImageContainer">
    <img src="@Model.CampaignBundle.Campaign.ImageUrl" name="img" id="img" style="width: 100%;">
</div>

<div class="divContent">
    <div style="margin-top: 0.06rem" class="campaignName">
        @Model.CampaignBundle.Campaign.Name
    </div>
    <div style="margin-top: 0.06rem" class="campaignDescription">
        @Html.Raw(Model.CampaignBundle.Campaign.Introduction)
    </div>

   

   
  
    @*<div style="text-align:center">
            <div class="divVote" style="margin-top: 0.1rem;" onclick="showCampaignDescription()">
                查看活动详情
            </div>
        </div>*@

    @*<div style="text-align: center; margin-top: 0.1rem;">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="33%" align="center">
                    参与人数<br />
                    <span class="defaultColor" style="font-weight:bold">@Model.DataReport.MemberCount</span>
                </td>
                <td width="33%" align="center">
                    总号码数<br />
                    <span class="defaultColor" style="font-weight:bold">@Model.DataReport.LuckyTicketCount</span>
                </td>
                <td width="33%" align="center">
                    围观次数<br />
                    <span class="defaultColor" style="font-weight:bold">@Model.DataReport.PageVisitCount</span>
                </td>
            </tr>
        </table>
    </div>*@

    <div class="divDotLine" style="margin-top:0.05rem; margin-bottom:0.1rem;">
    </div>
    @*<div id="divMemberInfo" onclick="showShareMask()">
        <table border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td align="left" style="width:0.3rem"><img src="/Content/Images/shareTimeLine.jpg" style="width:0.2rem;"></td>
                <td align="left"><div style="line-height:0.2rem">点击这里分享本页试一试~</div></td>
            </tr>
        </table>
    </div>*@


    <div class="divDotLine" style="margin-top:0.05rem; margin-bottom:0.1rem;">
    </div>

    <form id="form">
        <div style="font-size:0.14rem;">
            捐款金额（元）：
        </div>
        <div style="margin-top:0.1rem;">
            <input id="txtFee" name="txtFee" type="text" class="input_16" value="" maxlength="6">
        </div>
        <div style="font-size:0.14rem;margin-top:0.2rem;">
            姓名：
        </div>
        <div style="margin-top:0.1rem;">
            <input id="txtName" name="txtName" type="text" class="input_16" value="" maxlength="25">
        </div>
        <div style="font-size:0.14rem;margin-top:0.2rem;">
            联系方式：
        </div>
        <div style="margin-top:0.1rem;">
            <input id="txtContact" name="txtContact" type="text" class="input_16" value="" maxlength="50">
        </div>
        <div style="font-size:0.14rem;margin-top:0.2rem;">
            爱心留言：
        </div>
        <div style="margin-top:0.1rem;">
            <input id="txtDescription" name="txtDescription" type="text" class="input_16" value="" maxlength="250">
        </div>
        <div style="margin-top:0.3rem; margin-left:auto; margin-right:auto;width:1.5rem;">
            <input name="" type="button" class="button" value="确 认" style="width:100%" onclick="deposit()" @if (ViewBag.DomainContext.Pay == false) { @Html.Raw("disabled")   }>
        </div>
    </form>
    @if (ViewBag.DomainContext.Pay == false)
    {
        <div style="margin-top:0.2rem;">
            <span>@(ViewBag.Authorizer.NickName) 未开通对接微信支付。</span>
        </div>
    }

    <div class="divDotLine" style="margin-top:0.1rem; margin-bottom:0.1rem;">
    </div>
    <div>
        我的捐款记录：
    </div>
    <div style="margin-top:0.1rem;" id="ticketNumberItemContainer">

    </div>

    <div style="margin-top:0.1rem;">
        华晶文化：做事争做奋斗者，做人要有情有义
    </div>
</div>

<div id="divFooter">
    <table align="center" border="0" style="height:100%;width:100%">
        <tr>
            <td valign="middle" align="center" width="50%">
                <input name="" type="button" class="button" value="活动说明" style="width:90%" onclick="showCampaignDescription()">
            </td>
            @*<td valign="middle" align="center" width="50%">
                <input name="" type="button" class="button" value="开奖信息" style="width:90%" onclick="showDrawResult()">
            </td>*@
        </tr>
    </table>
</div>

<div id="divShareMask" style="display:none" onclick="hideShareMask()">
    <img src="/Content/Images/share.PNG" width="200" height="145">
</div>

